rm(list = setdiff(ls(), lsf.str()))
load("Study 1/Altered Data/Study 1_US_ANES2016.Rdata")

### Results belonging to Figure 1------

### vote choice
trump_vote<-list()
trump_vote[[1]] <- glm(vote_trump ~ zero1(agreeableness) + zero1(openness) + zero1(conscientiousness) + zero1(extraversion) + zero1(neuroticism) + zero1(authoritarianism) + female + age +  black + Indian + Asian + Hawaiian + Other, data=data, family="binomial")

trump_vote[[2]] <- glm(vote_trump ~ zero1(agreeableness) + zero1(openness) + zero1(conscientiousness) + zero1(extraversion) + zero1(neuroticism) + zero1(authoritarianism) +  female + age +  black + Indian + Asian + Hawaiian + Other + edu2 + edu3 + edu4 + edu5 + edu6 + edu7 + income + income_missing + zero1(post_lib_cons_placement), data=data, family="binomial")

labels <- c("Agreeableness", "Openness", "Conscientiousness", "Extraversion", "Neuroticism","Authoritarianism", "Female", "Age", "Black", "American Indian", "Asian","Native Hawain", "Other",  "High school graduate", "Some college", "2 years degree", "4 years degree", "Professional degree", "Doctorate", "Other", "Income", "Income missing", "Ideology")
stargazer2(trump_vote, odd.ratio=TRUE, title="US 2016: Vote for Donald Trump", align=TRUE,  omit.stat=c("LL","ser","f", "adj.rsq"), star.cutoffs=c(0.05), covariate.labels = labels,  column.labels = c("Base", "Figure 1"), dep.var.labels.include = FALSE, model.numbers= FALSE, font.size = "tiny", notes = "Odds ratios with standard errors from logistic regression models; *p<0.05",  notes.append = FALSE, no.space=TRUE, out="Tables/ANESvote.tex", label="tab:US_vote_results" )

### Correlation matrix-------------------------
myvars <- c("agreeableness", "openness", "conscientiousness", "extraversion", "neuroticism","authoritarianism", "post_lib_cons_placement")
cor_ivs <- data[myvars]
names(cor_ivs) <- c("1. Agreeableness","2. Opennesss","3. Conscientiousness",
                    "4. Extraversion", "5. Neuroticism", 
                    "6. Authoritarianism", "7. Ideology")
correlation.matrix <- cor(cor_ivs, use="complete.obs")

correlation.matrix <- data.frame(get_lower_tri(correlation.matrix))
correlation.matrix<-correlation.matrix[,c(1:7)]
names(correlation.matrix) <- seq(1,7,1)
correlation.matrix<-as.matrix(correlation.matrix)
stargazer(correlation.matrix, title="ANES: Correlation Matrix of Independent Variables", out="Tables/ANES_cor.tex", no.space=TRUE, label="tab:ANES_cor", digits=2)

### Desciptive statistics ----------------
desc.labels <- c("Populist Vote", labels)
stargazer(trump_vote[[2]]$model, covariate.labels=desc.labels,type = "latex", summary.stat = c("mean", "sd", "median", "min",  "max"), title="Descriptive statistics ANES US", out="Tables/US_descrip.tex", no.space=TRUE, label="tab:US_descriptives", digits=2) 

### Controlling for partisanship---------------------

### vote choice
trump_vote<-list()
trump_vote[[1]] <- glm(vote_trump ~ zero1(agreeableness) + zero1(openness) + zero1(conscientiousness) + zero1(extraversion) + zero1(neuroticism) + zero1(authoritarianism) +  female + age +  black + Indian + Asian + Hawaiian + Other, data=data, family="binomial")

trump_vote[[2]] <- glm(vote_trump ~ zero1(agreeableness) + zero1(openness) + zero1(conscientiousness) + zero1(extraversion) + zero1(neuroticism) + zero1(authoritarianism) +  female + age +  black + Indian + Asian + Hawaiian + Other + edu2 + edu3 + edu4 + edu5 + edu6 + edu7 + income + income_missing + partyidentity, data=data, family="binomial")

stargazer2(trump_vote, odd.ratio=TRUE, title="US 2016: Vote for Donald Trump controlling for partianship", align=TRUE,  omit.stat=c("LL","ser","f", "adj.rsq"), star.cutoffs=c(0.05), covariate.labels = labels,
          column.labels = c("Base", "Figure 1"), dep.var.labels.include = FALSE, model.numbers= FALSE, font.size = "tiny", notes = "Odds ratios with standard errors from logistic regression models; *p<0.05",  notes.append = FALSE, no.space=TRUE, out="Tables/ANESvote_partisan.tex", label="tab:US_vote_results_partisan" )

